# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=gsad
pkgver=24.0.0
pkgrel=0
pkgdesc="Greenbone Security Assistant HTTP Server - The server talking to the Greenbone Vulnerability Management (GVM) deamon"
url="https://www.openvas.org/"
arch="all !riscv64 !loongarch64 !s390x !x86 !ppc64le" # limited by gsa
license="AGPL-3.0-or-later"
pkgusers="gvm"
pkggroups="gvm"
depends="gsa"
makedepends="
	cgreen-dev
	cmake
	doxygen
	glib-dev
	graphviz
	gvm-libs-dev
	libgcrypt-dev
	libmicrohttpd-dev
	libxml2-dev
	libxslt-dev
	py3-polib
	samurai
	xmltoman
	"
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/gsad/archive/refs/tags/v$pkgver.tar.gz
	fix-bin-path.patch
	$pkgname.initd
	$pkgname.logrotate"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSYSCONFDIR=/etc \
		-DGSAD_PID_PATH=/run/gsad/gsad.pid \
		-DGVMD_RUN_DIR=/run/gvmd \
		-DGSAD_RUN_DIR=/run/gsad \
		-DLOCALSTATEDIR=/var \
		-DLOGROTATE_DIR=/etc/logrotate.d \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)"

	cmake --build build

	# -DBUILD_TESTING toggles the gsad-validator-test target
	# Build test executable from target
	if want_check; then
		cmake --build build --target gsad-validator-test
	fi
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	rm -rf "$pkgdir"/lib/systemd
}

sha512sums="
27b6f27e1da5c587c60b0d9afc4f912f174fd4438a93ad23cf538a4424ce6a5b5ae3dbb6f47a10a9e6f163c67047ad193d7a57210675aa75d7a382d586ec5220  gsad-24.0.0.tar.gz
2004f92b395695684ea827afbee7d5177980491ae516f449630a848c9145cbffeb882836860e3d70944f34699a38a3e6739f926073d81284e29b2cb2f4ad861b  fix-bin-path.patch
70db1ef2b79dba7e13dd8d24acd0432828387e313fce4e922873cb95a958e7071c4731d32abd63453c4a7b397ea7433a1c52c478a893f99e3c14304dccfd6042  gsad.initd
ae2e030a4e0a6cb3022706d64d65990ee8fafb36dbff2e76478e68748a2c1deca1679408ea029140f08e0d32cf8060475f9c763a263252cff80a86047101dab0  gsad.logrotate
"
